package cn.ljy.mes.service.impl;

import cn.ljy.authority.service.impl.IBaseService;
import cn.ljy.mes.dao.mapper.WmsMaterialBatchMapper;
import cn.ljy.mes.dao.mapper.WmsMaterialInventoryDetailMapper;
import cn.ljy.mes.dao.mapper.WmsMaterialInventoryDetailRelocationLogMapper;
import cn.ljy.mes.dao.mapper.WmsWarehouseSeatMapper;
import cn.ljy.mes.model.WmsMaterialInventoryDetailLockLog;
import cn.ljy.mes.model.query.WmsMaterialInventoryDetailLockLogQuery;
import cn.ljy.mes.service.WmsMaterialInventoryDetailLockLogService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;

import java.util.List;

@Service
//@Transactional(propagation = Propagation.REQUIRED,isolation = Isolation.DEFAULT,timeout=36000,rollbackFor= MyRollBackException.class)
@Validated//表示开启sprint的校检框架，会自动扫描方法里的@Valid（@Valid注解一般写在接口即可）
@Slf4j
public class IWmsMaterialInventoryDetailLockLogService extends IBaseService<WmsMaterialInventoryDetailLockLog, WmsMaterialInventoryDetailLockLogQuery> implements WmsMaterialInventoryDetailLockLogService {
    @Autowired
    private WmsMaterialInventoryDetailMapper materialInventoryDetailMapper;
    @Autowired
    private WmsMaterialBatchMapper materialBatchMapper;
    @Autowired
    private WmsWarehouseSeatMapper wmsWarehouseSeatMapper;
    @Autowired
    private WmsMaterialInventoryDetailRelocationLogMapper materialInventoryDetailRelocationLogMapper;

    @Override
    protected void afterFindAll(List<WmsMaterialInventoryDetailLockLog> list) {
        for(WmsMaterialInventoryDetailLockLog materialInventoryDetailLockLog:list){
            //锁定数量
            if(materialInventoryDetailLockLog.getLockType().equals("unlock")){
                materialInventoryDetailLockLog.setDeltaQuantity(-materialInventoryDetailLockLog.getDeltaQuantity());
            }
            materialInventoryDetailLockLog.setDeltaQuantityString(String.format("目标库位（%s->%s->%s）%s：%d->%d",
                    materialInventoryDetailLockLog.getWarehouse(),
                    materialInventoryDetailLockLog.getArea(),
                    materialInventoryDetailLockLog.getSeat(),
                    materialInventoryDetailLockLog.getLockType().equals("unlock")?"解锁":"锁定",
                    materialInventoryDetailLockLog.getPreLockedQuantity(),
                    materialInventoryDetailLockLog.getPreLockedQuantity()+materialInventoryDetailLockLog.getDeltaQuantity()
            ));
        }
    }
}
